package cn.kduck.web.gmd.client;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.Widget;
import gwt.material.design.addins.client.window.MaterialWindow;
import gwt.material.design.client.ui.MaterialButton;
import gwt.material.design.client.ui.MaterialTextBox;

public class HomeView implements EntryPoint {

    interface MyUiBinder extends UiBinder<Widget, HomeView> {}
    MyUiBinder uiBinder = GWT.create(MyUiBinder.class);

    @UiField
    MaterialWindow loginWindow;

    @UiField
    MaterialTextBox usernameTextBox;
    @UiField
    MaterialTextBox passwordTextBox;

    @UiField
    MaterialButton loginButton;

    private Widget root;
    @Override
    public void onModuleLoad() {
        root = uiBinder.createAndBindUi(this);
        RootPanel.get().add(root);
        loginWindow.getIconMaximize().setVisible(false);
        loginWindow.getIconClose().setVisible(false);
        loginWindow.open();

        usernameTextBox.setValidateOnBlur(false);
        passwordTextBox.setValidateOnBlur(false);
    }

    @UiHandler("loginButton")
    void handleClick(ClickEvent e) {
        RootPanel.get().remove(root);
//        loginWindow.validate();
        MainPage mainPage = new MainPage();
        RootPanel.get().add(mainPage);
    }

}
